<template>
    <div class="lb-customer-question-setting">
        <top-nav></top-nav>
        <div class="page-main">
            <el-form @submit.native.prevent :model="setForm" :rules='setFormRules' ref="setForm" label-width="120px" class='set-form'>
                <el-form-item label="问卷开关" prop='question_switch'>
                   <el-radio-group v-model="setForm.question_switch">
                        <el-radio :label="0">关闭</el-radio>
                        <el-radio :label="1">开启</el-radio>
                    </el-radio-group>
                    <lb-tool-tips>是否开启问卷功能, 开启此开关后, 小程序端会显示对应的问卷入口</lb-tool-tips>
                </el-form-item>
                <el-form-item label="问卷按钮" prop='question_text'>
                    <el-input v-model="setForm.question_text" placeholder="请输入按钮文字"></el-input>
                    <lb-tool-tips>开启问卷后, 小程序端进入问卷入口按钮显示文字</lb-tool-tips>
                </el-form-item>
                <el-form-item>
                    <lb-button type='primary' @click="submitFormInfo">{{$t('action.submit')}}</lb-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
export default {
  data () {
    return {
      setForm: {
        question_switch: 0,
        question_text: ''
      },
      setFormRules: {
        question_switch: {required: true, message: '请选择对否开启', type: 'number', trigger: 'change'},
        question_text: {required: true, message: '请输入按钮文字', type: 'string', trigger: 'blur'}
      }
    }
  },
  created () {
    this.getFormInfo()
  },
  methods: {
    getFormInfo () {
      this.$api.getCustomerQuestionConfigInfo().then(res => {
        if (res.code === 200) {
          this.setForm = res.data
        }
      })
    },
    submitFormInfo () {
      this.$refs['setForm'].validate(valid => {
        if (valid) {
          let {setForm} = this
          this.$api.settingCustomerQuestionConfigInfo({data: setForm}).then(res => {
            if (res.code === 200) {
              this.$message.success(this.$t('tips.successSub'))
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
    .lb-customer-question-setting{
        width: 100%;
        .page-main{
            width: 100%;
            .set-form{
                .el-input{
                    width: 300px;
                }
            }
        }
    }
</style>
